package com.wd.live.model.base
import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import java.lang.Exception
import java.lang.reflect.Method
import java.lang.reflect.ParameterizedType



/**
 * 作者：马海钊
 * 时间：2023/8/14 15:51
 * 功能：
 */
abstract class BaseActivity<VM : BaseViewModel, VDB : ViewBinding> : AppCompatActivity() {
    protected lateinit var binding:VDB
    protected lateinit var viewModel: VM
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding=getViewBinding();
        setContentView(binding.root)
        initData()
        initviewModel()
    }
    protected fun initviewModel(){
        val type=javaClass.genericSuperclass
        val aclass=(type as ParameterizedType).actualTypeArguments[0]as Class<ViewModel>
        viewModel=ViewModelProvider(this).get(aclass) as VM
    }
    protected abstract fun initData();
    protected abstract fun getViewBinding():VDB
}
